package com.haocean.project.model.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.util.Assert;


/**
 * @author smartye
 */
public class Page {

    public interface ListView {
    }

    public Page() {
    }

    private Integer page = 0;

    private Integer size = 15;

    private Long total;

    private Long totalPage;

    private Object content;

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        Assert.isTrue(page >= 0, "分页信息错误！");
        this.size = size;
    }

    @JsonIgnore
    public long getOffset() {
        return page * size;
    }

    @JsonIgnore
    public Integer getLimit() {
        return size;
    }

    public Object getContent() {
        return content;
    }

    public void setContent(Object content) {
        this.content = content;
    }

    public void setTotal(Long total) {
        this.total = total;
        if (total % size == 0) {
            this.totalPage = total / size;
        } else {
            this.totalPage = total / size + 1;
        }
    }

    public Long getTotal() {
        return total;
    }

    public Long getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Long totalPage) {
        this.totalPage = totalPage;
    }

    @Override
    public String toString() {
        return "Page{" +
                "page=" + page +
                ", size=" + size +
                ", total=" + total +
                ", totalPage=" + totalPage +
                ", content=" + content +
                '}';
    }
}
